#ifndef MKAHYPAR_RANDOM_INITIAL_PARTITIONER_H
#define MKAHYPAR_RANDOM_INITIAL_PARTITIONER_H

#include "mkahypar/partition/initial_partitioning/i_initial_partitioner.h"
#include "mkahypar/partition/initial_partitioning/initial_partitioner_base.h"
//#include "mkahypar/utils/randomize.h"
//纯随机初始解
namespace mkahypar {
  class RandomInitialPartitioner : public IInitialPartitioner,
                                   public InitialPartitionerBase<RandomInitialPartitioner> {
    using Base = InitialPartitionerBase<RandomInitialPartitioner>;
  public:
    RandomInitialPartitioner(Hypergraph &hypergraph, TargetGraph &targetGraph) :
            Base(hypergraph, targetGraph) {
    }

    void initialPartition() {
      //每个点随机分配
      std::vector<HypernodeID> unsigned_nodes;
      for (auto v: _hg.nodes())
        unsigned_nodes.push_back(v);
      Randomize::getInstance().shuffleVector(unsigned_nodes, unsigned_nodes.size());

      for (auto hn: unsigned_nodes) {
        PartitionID id = Randomize::getInstance().getRandomInt(0, _hg._k - 1);
        LOG<<"assign"<<hn<<"to"<<id;
        setNodePart(hn, id);
      }
      //初始话切割
      for (HypernodeID hn = 0; hn < _hg.initialNumNodes(); ++hn)
        _hg.hypernode(hn).num_incident_cut_hes = 0;
      for (const HyperedgeID &he: _hg.edges()) {
        if (_hg.connectivity(he) > 1) {
          for (const HypernodeID &pin: _hg.pins(he)) {
            ++_hg.hypernode(pin).num_incident_cut_hes;
          }
          //遍历切边的所有联通分区
          auto x = _hg.hyperedge(he).connectivity._n;
          for (PartitionID id = 0; x && id < _hg._k; ++id, x >>= 1) {
            if (x & 1) {
              _topo._fpga[id]._used_line += _hg.hyperedge(he).weight();
            }
          }
        }
      }
      //


    }

  private:

    void partitionImpl() override final {
      Base::singleRunsInitialPartitioning();
    }
  };
}
#endif //MKAHYPAR_RANDOM_INITIAL_PARTITIONER_H
